package com.pml.dbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DatabaseConnection {
    private static final String DBDRIVER="com.mysql.jdbc.Driver";
    private static final String DBURL="jdbc:mysql://localhost:3306/test";
    private static final String DBUSER="root";
    private static final String DBPASSWORD="root";
    private Connection conn;

    public Connection getConnection() throws Exception{
        Class.forName(DBDRIVER);
        this.conn= DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);
        return conn;
    }

    public void close() throws Exception{
        if (conn!=null) {
            try {
                this.conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
                throw e;
            }
        }
    }
}
